package gob.osinerg.emergencia.tag;

import org.apache.log4j.Logger;

public class GenericControl {
	Logger log = Logger.getLogger(GenericControl.class);
	private String OPEN_TAG="<input ";
	private String CLOSE_TAG="/>";
	//Styles
	private String styleId = null;
	private String style = null;
	private boolean disabled = false;
	private String styleClass = null;
	
	private String size = null;
	private String title = null;
	private boolean readonly = false;
	private boolean enabled = true;
	
	private String type = null;
    protected String accesskey = null;
    private String alt = null;
    
    protected String accept = null;
    protected String tabindex = null;
    
    private String name=null;
	private String maxLength;
	// Events
	private String onblur = null;
	private String onchange = null;
	private String onclick = null;
	private String ondblclick = null;
	private String onfocus = null;
	private String onkeydown = null;
	private String onkeypress = null;
	private String onkeyup = null;
	private String onmousedown = null;
	private String onmousemove = null;
	private String onmouseout = null;
	private String onmouseover = null;
	private String onmouseup = null;
	private String onselect = null;
	private String onrelease = null;
	private String value= null;
	
	private String control;
	private String label;
	private String id;
	private String required;
	public String getControl() {
		return control;
	}

	public void setControl(String control) {
		this.control = control;
	}

	public void prepareAttribute(StringBuffer handlers,String name, Object value){
		
		if (value!=null){
			handlers.append(" ");
            handlers.append(name);
            handlers.append("=\"");
            handlers.append(value);
            handlers.append("\"");
		}
		
	}
	
	public void addElements(StringBuffer handlers,String name, Object value){
		
		if (value!=null){
			handlers.append(" ");
            handlers.append(name);
            handlers.append("=\"");
            handlers.append(value);
            handlers.append("\"");
		}
		
	}
	public StringBuffer getHtml(StringBuffer html) {
		
		
		prepareAttribute(html, "type", getType());
		prepareAttribute(html, "name", getName());
		prepareAttribute(html, "value", getValue());
		prepareAttribute(html, "accesskey", getAccesskey());
		prepareAttribute(html, "accept", getAccept());
		prepareAttribute(html, "maxlength", getMaxLength());
		prepareAttribute(html, "size", getSize());
		prepareAttribute(html, "tabindex", getTabindex());
		prepareAttribute(html, "onclick", getOnclick());
		prepareAttribute(html, "readonly", getReadonly() ? "readonly" : null);
		prepareAttribute(html, "disabled", getDisabled() ? "disabled" : null);
		prepareAttribute(html, "onkeyup", getOnkeyup());
		prepareAttribute(html, "onblur", getOnblur());
		prepareAttribute(html, "onkeypress", getOnkeypress());
		return html;
	}
	public void openTag(StringBuffer sb){
		sb.append("<"+getControl());
	}
	
	public void closeTag(StringBuffer sb){
		sb.append(" />");
	}
	


	public String getStyleId() {
		return styleId;
	}



	public void setStyleId(String styleId) {
		this.styleId = styleId;
	}



	public String getStyle() {
		return style;
	}



	public void setStyle(String style) {
		this.style = style;
	}



	public boolean getDisabled() {
		return disabled;
	}



	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}



	public String getStyleClass() {
		return styleClass;
	}



	public void setStyleClass(String styleClass) {
		this.styleClass = styleClass;
	}



	public String getSize() {
		return size;
	}



	public void setSize(String size) {
		this.size = size;
	}



	public String getTitle() {
		return title;
	}



	public void setTitle(String title) {
		this.title = title;
	}



	public boolean getReadonly() {
		return readonly;
	}



	public void setReadonly(boolean readonly) {
		this.readonly = readonly;
	}



	public String getType() {
		return type;
	}



	public void setType(String type) {
		this.type = type;
	}



	public String getAccesskey() {
		return accesskey;
	}



	public void setAccesskey(String accesskey) {
		this.accesskey = accesskey;
	}



	public String getAlt() {
		return alt;
	}



	public void setAlt(String alt) {
		this.alt = alt;
	}



	public String getAccept() {
		return accept;
	}



	public void setAccept(String accept) {
		this.accept = accept;
	}



	public String getTabindex() {
		return tabindex;
	}



	public void setTabindex(String tabindex) {
		this.tabindex = tabindex;
	}



	public String getOnblur() {
		return onblur;
	}



	public void setOnblur(String onblur) {
		this.onblur = onblur;
	}



	public String getOnchange() {
		return onchange;
	}



	public void setOnchange(String onchange) {
		this.onchange = onchange;
	}



	public String getOnclick() {
		return onclick;
	}



	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}



	public String getOndblclick() {
		return ondblclick;
	}



	public void setOndblclick(String ondblclick) {
		this.ondblclick = ondblclick;
	}



	public String getOnfocus() {
		return onfocus;
	}



	public void setOnfocus(String onfocus) {
		this.onfocus = onfocus;
	}



	public String getOnkeydown() {
		return onkeydown;
	}



	public void setOnkeydown(String onkeydown) {
		this.onkeydown = onkeydown;
	}



	public String getOnkeypress() {
		return onkeypress;
	}



	public void setOnkeypress(String onkeypress) {
		this.onkeypress = onkeypress;
	}



	public String getOnkeyup() {
		return onkeyup;
	}



	public void setOnkeyup(String onkeyup) {
		this.onkeyup = onkeyup;
	}



	public String getOnmousedown() {
		return onmousedown;
	}



	public void setOnmousedown(String onmousedown) {
		this.onmousedown = onmousedown;
	}



	public String getOnmousemove() {
		return onmousemove;
	}



	public void setOnmousemove(String onmousemove) {
		this.onmousemove = onmousemove;
	}



	public String getOnmouseout() {
		return onmouseout;
	}



	public void setOnmouseout(String onmouseout) {
		this.onmouseout = onmouseout;
	}



	public String getOnmouseover() {
		return onmouseover;
	}



	public void setOnmouseover(String onmouseover) {
		this.onmouseover = onmouseover;
	}



	public String getOnmouseup() {
		return onmouseup;
	}



	public void setOnmouseup(String onmouseup) {
		this.onmouseup = onmouseup;
	}



	public String getOnselect() {
		return onselect;
	}



	public void setOnselect(String onselect) {
		this.onselect = onselect;
	}



	public String getOnrelease() {
		return onrelease;
	}



	public void setOnrelease(String onrelease) {
		this.onrelease = onrelease;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getMaxLength() {
		return maxLength;
	}

	public void setMaxLength(String maxLength) {
		this.maxLength = maxLength;
	}

	public boolean getEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String toString() {
		StringBuffer sb = new StringBuffer();
		sb.append(OPEN_TAG);
		addElements(sb, "type", getType());
		addElements(sb, "name", getName());
		addElements(sb, "value", getValue());
		addElements(sb, "accesskey", getAccesskey());
		addElements(sb, "accept", getAccept());
		addElements(sb, "maxlength", getMaxLength());
		addElements(sb, "size", getSize());
		addElements(sb, "tabindex", getTabindex());
		addElements(sb, "onclick", getOnclick());
		addElements(sb, "readonly", getReadonly() ? "readonly" : null);
		addElements(sb, "disabled", getDisabled() ? "disabled" : null);
		addElements(sb, "onkeyup", getOnkeyup());
		addElements(sb, "onkeypress", getOnkeypress());
		sb.append(CLOSE_TAG);
		
		return sb.toString();
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getRequired() {
		return required;
	}

	public void setRequired(String required) {
		this.required = required;
	}
	
	
	
}
